gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\generalp\pnmix.m

    function [hellipse,hcenter]=pnmix(X,MI,SIGMA,I,hellipse,hcenter)
%  [hellipse,hcenter]=pnmix(X,MI,SIGMA,I,hellipse,hcenter)
%
% PNMIX vizualizes mixture of normal distributions in 2D space. 
%  Each normal distribution is determined by a pair of mean values and 
%  covariance matrix. The mean value is vizualized as a point and the 
%  covariance matrix as en ellipse. A size of the ellipse is determined 
%  in order to contain all the points belonging to given class which 
%  the ellipse describes.
%
%  Input and output arguments hellipse and hcenter contain
%  handles of graphics objects (ellipses and their centers) and
%  if they enter the function, the old graphics objects vanish and 
%  then new objects are plotted.
%
%  The function is useful for vizualization of results of the unsupervised
%  learning algorithms (see help of UNSUNI, UNSUND).
%
% Input:
%   X [NxK] contains K points which are N-dimensional, X=[x_1,x_2,...,x_K].
%   I [1xK] contains class labels for all the points.
%   MI [NxM] mean values for each class, MI=[mi_1,mi_2,...,mi_M]
%   SIGMA [Nx(MxN)] covariance matrices for each class,
%      SIGMA=[sigma_1,sigma_2,...,sigma_M].
%   hellipse [vector], hcenter [vector] handlers of graphics objects.
%
% Output:
%   hellipse [vector], hcenter [vector] handlers of graphics objects.
%
% See also UNSUNI, UNSUND, UNSUDEMO.
%


% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac
% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz
% Written Vojtech Franc (diploma thesis) 10.11.1999, 23.12.1999
% Modifications:
% 22. 6.00 V. Hlavac, comments polished.


if nargin < 5,
  hellipse=-1;
end

DIM=size(X,1);
N=size(X,2);
K=size(MI,2);
maxr=zeros(1,K);
for i=1:N,
   r=sqrt(mahalan(X(:,i),MI(:,I(i)),SIGMA(:,(I(i)-1)*DIM+1:DIM*I(i))));
   if maxr(I(i)) < r,
      maxr(I(i)) = r;
   end
end

if hellipse==-1,
   for i=1:K,
%%%      [x,y]=ellipse(inv(SIGMA(:,(i-1)*DIM+1:DIM*i)),30,maxr(i),MI(:,i));
      [x,y]=ellips(MI(:,i),SIGMA(:,(i-1)*DIM+1:DIM*i),maxr(i),30);
      hellipse(i)=plot(x,y,'k','EraseMode','xor');
      hcenter(i)=plot(MI(1,i),MI(2,i),'+k','EraseMode','xor');
      drawnow;
   end
else
   for i=1:K,
%%%      [x,y]=ellipse(inv(SIGMA(:,(i-1)*DIM+1:DIM*i)),30,maxr(i),MI(:,i));
      [x,y]=ellips(MI(:,i),SIGMA(:,(i-1)*DIM+1:DIM*i),maxr(i),30);
      set(hellipse(i),'XData',x,'YData',y,'Visible','on');
      set(hcenter(i),'XData',MI(1,i),'YData',MI(2,i),'Visible','on');
      drawnow;
   end
end